import pygame.image

class Settings():
    """储存《外星人入侵》的所有设置的类"""

    def __init__(self):
        """初始化游戏的设置"""
        # 屏幕设置
        self.screen_width = 1200
        self.screen_height = 900

        # 屏幕滚动速度设置
        self.background_sroll_speed = 0.01

        # 飞船速度设置
        self.ship_speed_factor = 7
        self.ship_limit = 3

        # 外星人速度与移动设置

        self.fleet_drop_speed = 10      # 撞到边缘时。向下移动的速度
        self.fleet_ind_drop_speed = 10
        self.fleet_direction = 1

        # 子弹设置
        self.bullet_speed_factor = 15
        self.bullet_width = 6
        self.bullet_height = 15
        self.bullet_color = (0, 255, 255)
        self.bullets_allowed = 5    # 同屏允许存在的子弹数量

        # 敌军子弹设置
        self.enemy_bullet_width = 3
        self.enemy_bullet_height = 15
        self.enemy_bullet_color = (255, 255, 0)       # 黄色
        self.enemy_bullet_speed_factor = 5

        # 发射冷却
        self.bullet_cooldown = 0.3  # 发射间隔（秒）
        self.last_shot_time = 0     # 记录上次发射时间

        # 撞击冷却
        self.crash_cooldown = 1   # 撞击间隔（秒）
        self.last_crash_time = 0    # 记录上次撞击事件

        # 音效设置
        self.load_sounds()  # 新增音效加载方法

    def load_backgrounds(self):
        """加载背景图片并初始化位置"""
        # 背景设置
        self.bg_img = (pygame.image.load(
            "D:/game_program/Alien_Invasion/Small 512x512/Blue Nebula/Blue_Nebula_02-512x512.png")
                       .convert())

        self.bg_width = self.bg_img.get_width()
        self.bg_height = self.bg_img.get_height()

        # 计算需要平铺的行数和列数
        self.tiles_x = (self.screen_width // self.bg_width) + 1     # 水平方向平铺数量
        self.tiles_y = (self.screen_height // self.bg_height) + 1   # 垂直方向平铺数量

        # 初始化背景位置偏移量
        self.bg_offset_y = 0.0
        self.bg_offset_x = 0.0

    def load_sounds(self):
        """加载游戏音效"""
        self.sound_on = True
        # 开火音效
        self.fire_sound = pygame.mixer.Sound("D:/game_program/Alien_Invasion/sounds/shot1.wav")
        self.fire_sound.set_volume(0.5)     # 音量调节

        # 击中音效
        self.hit_sound = pygame.mixer.Sound("D:/game_program/Alien_Invasion/sounds/hit.wav")
        self.hit_sound.set_volume(1.0)      # 音量调节

        # 撞击音效
        self.crash_sound = pygame.mixer.Sound("D:/game_program/Alien_Invasion/sounds/crash.wav")
        self.crash_sound.set_volume(0.2)  # 音量调节

        # 爆炸音效
        self.explosion_sound = pygame.mixer.Sound("D:/game_program/Alien_Invasion/sounds/explosion1.wav")
        self.explosion_sound.set_volume(0.5)

        # 被击音效
        self.self_hit_sound = pygame.mixer.Sound("D:/game_program/Alien_Invasion/sounds/hit.wav")
        self.self_hit_sound.set_volume(0.5)  # 音量调节
